<?php
/**.-------------------------------------------------------------------------------------------------------------------
 * |  Github: https://github.com/Tinywan
 * |  Blog: http://www.cnblogs.com/Tinywan
 * |--------------------------------------------------------------------------------------------------------------------
 * |  Author: Tinywan(ShaoBo Wan)
 * |  DateTime: 2019/1/15 16:07
 * |  Mail: 756684177@qq.com
 * |  Desc: 描述信息
 * '------------------------------------------------------------------------------------------------------------------*/

require_once dirname(dirname(__FILE__)).'/vendor/autoload.php';

$services = [
    '192.168.10.1' => 5,
    '192.168.10.2' => 1,
    '192.168.10.3' => 1,
];
$robin = new \Robin\SmoothWeightedRobin();
$robin->init($services);

$nodes = [];
$sumWeight = $robin->getSumWeight();
for ($i = 1; $i <= $sumWeight; $i++) {
    $node = $robin->next();
    $nodes[$i] = $node;
}
var_export($nodes);

//array (
//    1 => '192.168.10.1',
//    2 => '192.168.10.1',
//    3 => '192.168.10.2',
//    4 => '192.168.10.1',
//    5 => '192.168.10.3',
//    6 => '192.168.10.1',
//    7 => '192.168.10.1',
//)